<?php
include dirname(__FILE__)."/../utils/utils.php";
session_start();
if(!Utils::isLoggedIn()){
	die('You are not allowed to access this page.');
}
	echo "letterId: ".$_POST['letterid'];
	echo "teamName: ".$_POST['teamName'];
	echo "teamId: ".$_POST['teamId'];
	$teamId = isset($_POST['teamId'])?$_POST['teamId']:"-1";
	include "dbmanager.php";
	$pDatabase = Database::getInstance();
	$sql="";
	if ($teamId == "-1") {
		$sql="INSERT INTO team (teamName, letterId) VALUES ('".$_POST['teamName']."', ".$_POST['letterid'].")";
		echo "<br/> sql: ".$sql;
		
		echo "insert volt";
	} else {
		$sql="UPDATE team SET teamName = '".$_POST['teamName']."', letterId = ".$_POST['letterid']." WHERE id = ".$teamId;
		echo "update volt";
	}
	$result = $pDatabase->query($sql);
	if (!$result) {
		die('Error: ' . mysql_error());
	} else {
		header("Location: ../../index.php?site=admin");
	}
	
	//
?>